import axios from "axios";
import { RoleDto, RoleVo } from "@/types/modules/system";

const contentPath = '/system/role'


export function create(role: RoleDto) {
  return axios.post<boolean>(`${contentPath}`, role)
}

export function grantAuthorities(roleId: number, authoritiesId: number[]) {
  return axios.put<boolean>(`${contentPath}/grant/${roleId}/authorities`, authoritiesId)
}

export function update(role: RoleDto) {
  return axios.put<boolean>(`${contentPath}`, role)
}

export function deleteById(id: number) {
  return axios.delete<boolean>(`${contentPath}/${id}`)
}

export function findById(id: number) {
  return axios.get<RoleVo>(`${contentPath}/${id}`)
}

export function listAll() {
  return axios.get<RoleVo[]>(`${contentPath}/list`);
}

export function listJoinsWithAuthorityId(id: number) {
  return axios.get<number[]>(`${contentPath}/${id}/authorities-joins`)
}
